const AC_GAME_OOBJECTS=[];

export class AcGameObject {
    constructor(){
        AC_GAME_OOBJECTS.push(this);
        this.timedelta=0;
        this.has_called_start=false;
    }
    start(){//只执行一次

    }

    update(){ //每一帧执行一次，除了第一帧外

    }

    on_destory(){//删除之前的执行
    
    }
    destory(){
        this.on_destory();

        for(let i in AC_GAME_OOBJECTS){
            const obj =AC_GAME_OOBJECTS[i];
            if(obj === this){
                AC_GAME_OOBJECTS.splice(i);
                break;
            }
        }
    }
}

let last_timestamp;
const step= timestamp=>{
    for(let obj of AC_GAME_OOBJECTS){
        if(!obj.has_called_start){
            obj.has_called_start=true;
            obj.start();
        }else{
            obj.timedelta=timestamp-last_timestamp;
            obj.update();
        }
    }

    last_timestamp=timestamp;
    requestAnimationFrame(step)
}

requestAnimationFrame(step)